

// Node 链接 mongodb 数据库

const mongoose = require("mongoose")
const hostname = "0.0.0.0"
const port = 27017;
const dbname = "userinfo";

// const user = "zuozuomu"   //    数据库加密 
// const pass =  "missyou" 


const db_conn_str = `mongodb://${hostname}:${port}/${dbname}`

mongoose.connect(db_conn_str, {
    useNewUrlParser: true,
    useUnifiedTopology: true
}, (err) => {
    if (err) {
        console.log("数据库链接失败---" + err)
    } else {
        console.log("数据库链接成功---successful")
    }
})

var connection = mongoose.connection;

// 增删改查  

connection.on("connected", () => {
    console.log("数据库已经链接 --- connected")
})

connection.on("error", (err) => {
    console.log("数据库链接异常 --- " + err);
})

connection.on("disconnected", () => {
    console.log("数据库断开链接 --- disconnected")
})